package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class IteratorDemo {
    public static void main(String[] args) {
        Collection<String> c =new ArrayList<>();
        c.add("one");
        c.add("#");
        c.add("two");
        c.add("#");
        c.add("three");
        c.add("#");
        c.add("four");
        c.add("#");
        c.add("five");
        //c.add(123);//add(E e),由于实参不是sting类型,编译不通过

        Iterator<String> it =c.iterator();
        while (it.hasNext()){
            String e =it.next();
            System.out.println(e);
        }

        while (it.hasNext()){
            String e =it.next();
            if ("#".equals(e)){
               // c.remove(e);
                it.remove();
            }
            System.out.println(e);
        }
        System.out.println(c);
    }
}
